package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.domain.ReReport;
import com.ruoyi.service.IReReportService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;


import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 检测报告Controller
 *
 * @author ruoyi
 * @date 2025-08-11
 */
@RestController
@RequestMapping("/system/report")
public class ReReportController extends BaseController
{
    @Autowired
    private IReReportService reReportService;

    /**
     * 查询检测报告列表
     */
    @PreAuthorize("@ss.hasPermi('system:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReReport reReport)
    {
        startPage();
        List<ReReport> list = reReportService.selectReReportList(reReport);
        return getDataTable(list);
    }

    /**
     * 导出检测报告列表
     */
    @PreAuthorize("@ss.hasPermi('system:report:export')")
    @Log(title = "检测报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReReport reReport)
    {
        List<ReReport> list = reReportService.selectReReportList(reReport);
        ExcelUtil<ReReport> util = new ExcelUtil<ReReport>(ReReport.class);
        util.exportExcel(response, list, "检测报告数据");
    }

    /**
     * 获取检测报告详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(reReportService.selectReReportById(id));
    }

    /**
     * 新增检测报告
     */
    @PreAuthorize("@ss.hasPermi('system:report:add')")
    @Log(title = "检测报告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReReport reReport)
    {
        return toAjax(reReportService.insertReReport(reReport));
    }

    /**
     * 修改检测报告
     */
    @PreAuthorize("@ss.hasPermi('system:report:edit')")
    @Log(title = "检测报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReReport reReport)
    {
        return toAjax(reReportService.updateReReport(reReport));
    }

    /**
     * 删除检测报告
     */
    @PreAuthorize("@ss.hasPermi('system:report:remove')")
    @Log(title = "检测报告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(reReportService.deleteReReportByIds(ids));
    }
}
